﻿@Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "grid";
        settings.CallbackRouteValues = new { Controller = "MasterDetail", Action = "MasterDetailMasterPartial" };
        settings.Width = Unit.Percentage(100);
            
        settings.KeyFieldName = "CustomerID";
        settings.Columns.Add("ContactName");
        settings.Columns.Add("CompanyName");
        settings.Columns.Add("City");
        settings.Columns.Add("Country");
            
        settings.SettingsDetail.AllowOnlyOneMasterRowExpanded = false;
        settings.SettingsDetail.ShowDetailRow = true;

        settings.SetDetailRowTemplateContent(c => {
            ViewContext.Writer.Write(
                "Contact Phone: <b>" +
                    DataBinder.Eval(c.DataItem, "Phone") + "</b>, Fax: <b>" +
                        DataBinder.Eval(c.DataItem, "Fax") + "</b>" +
                "<br />" +
                "<br />"
            );
            Html.RenderAction("MasterDetailDetailPartial", new { CustomerID = DataBinder.Eval(c.DataItem, "CustomerID") });
        });
        settings.PreRender = (sender, e) => {
            ((MVCxGridView)sender).DetailRows.ExpandRow(0);
        };
    }).Bind(Model).GetHtml()
